<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>server</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" lay-filter="table-search">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">选择区服:</label>
                        <div class="layui-input-inline">
                            <select name="gameArea" class="layui-select" >
                                <option value="">全部</option>
                                <option v-for="(item,index) in services" :value="item.server_id">{{item.name}}</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">长ID</label>
                        <div class="layui-input-inline">
                            <input type="text" name="customerId" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">角色ID</label>
                        <div class="layui-input-inline">
                            <input type="text" name="roleId" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">时间</label>
                        <div class="layui-input-inline">
                            <input type="text" name="createTimeBegin" id="createTime0" placeholder="开始时间" autocomplete="off" class="layui-input" />
                            <input type="text" name="createTimeEnd" id="createTime1" placeholder="截止时间" autocomplete="off" class="layui-input" />
                        </div>
                    </div>
                <br>
                    <div class="layui-inline">
                        <label class="layui-form-label">榜单类型:</label>
                        <div class="layui-input-inline">
                            <select name="type" class="layui-select" >
                                <option value="">全部</option>
                                <option value="level">等级</option>
                                <option value="power">战力</option>
                                <option value="soul">魂侍</option>
                                <option value="enhance_times">强化次数</option>
                                <option value="refine_times">洗练次数</option>
                                <option value="wash_times">洗髓次数</option>
                                <option value="tower_floor">爬塔层数</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">


            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">

        </script>
    </div>
</div>

<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>
    new Vue({
        el: "#app",
        data: {
            services: JSON.parse(localStorage.getItem('services')),
        },
        mounted:function () {
            layui.use(['form', 'table','laydate'], function () {
                var isLodedTable = false;
                var $ = layui.jquery,
                    form = layui.form,
                    table = layui.table
                    ,laydate=layui.laydate;

                laydate.render({
                    elem: '#createTime0',
                    value: getYmd(0)
                });
                laydate.render({
                    elem: '#createTime1',
                    value: getYmd(1)
                });

                var loadTable = function(){
                    var getColsByType = function(type){
                        switch(type){
                            case 'level':
                                return [[
                                    {type: 'numbers', title: '排名', width: 80},
                                    {title: '角色名', width: 180, field: 'nick'},
                                    {title: '等级', width: 120, field: 'level'}
                                ]];
                            case 'power':
                                return [[
                                    {type: 'numbers', title: '排名', width: 80},
                                    {title: '角色名', width: 180, field: 'nick'},
                                    {title: '战力', width: 140, field: 'power'}
                                ]];
                            case 'soul':
                                return [[
                                    {type: 'numbers', title: '排名', width: 80},
                                    {title: '角色名', width: 180, field: 'nick'},
                                    {title: '角色名', width: 180, field: 'pet_name'},
                                    {title: '评分', width: 140, field: 'score'}
                                ]];
                            case 'enhance_times':
                                return [[
                                    {type: 'numbers', title: '排名', width: 80},
                                    {title: '角色名', width: 180, field: 'nick'},
                                    {title: '强化次数', width: 140, field: 'enhance_times'}
                                ]];
                            case 'refine_times':
                                return [[
                                    {type: 'numbers', title: '排名', width: 80},
                                    {title: '角色名', width: 180, field: 'nick'},
                                    {title: '洗练次数', width: 140, field: 'refine_times'}
                                ]];
                            case 'wash_times':
                                return [[
                                    {type: 'numbers', title: '排名', width: 80},
                                    {title: '角色名', width: 180, field: 'nick'},
                                    {title: '洗髓次数', width: 140, field: 'wash_times'}
                                ]];
                            case 'tower_floor':
                                return [[
                                    {type: 'numbers', title: '排名', width: 80},
                                    {title: '角色名', width: 180, field: 'nick'},
                                    {title: '层数', width: 140, field: 'tower_floor'}
                                ]];
                            default:
                                return [[
                                    {type: 'numbers', title: '排名', width: 80},
                                    {title: '角色名', width: 180, field: 'nick'}
                                ]];
                        }
                    };

                    var currentWhere = form.val('table-search');
                    var currentType = currentWhere && currentWhere.type ? currentWhere.type : '';

                    table.render({
                        where: currentWhere,
                        elem: '#currentTableId',
                        url: '/admin/customer/top',
                        defaultToolbar: ['filter', 'print' ],
                        toolbar: '#toolbarDemo',
                        cols: getColsByType(currentType),
                        limits: [10, 15, 20, 25, 50, 100],
                        limit: 15,
                        page: true,
                        skin: 'line'
                    });
                    isLodedTable = true;
                }

                loadTable();
                // 监听搜索操作
                form.on('submit(data-search-btn)', function (data) {
                    if (!isLodedTable){
                        loadTable();
                    } else {
                        //执行搜索重载，并根据榜单类型切换列
                        var whereObj = form.val('table-search');
                        var typeVal = whereObj && whereObj.type ? whereObj.type : '';
                        table.reload('currentTableId', {
                            page: { curr: 1 },
                            where: whereObj,
                            cols: (function(){
                                var mapCols = function(type){
                                    switch(type){
                                        case 'level':
                                            return [[
                                                {type: 'numbers', title: '排名', width: 80},
                                                {title: '角色名', width: 180, field: 'nick'},
                                                {title: '等级', width: 120, field: 'level'}
                                            ]];
                                        case 'power':
                                            return [[
                                                {type: 'numbers', title: '排名', width: 80},
                                                {title: '角色名', width: 180, field: 'nick'},
                                                {title: '战力', width: 140, field: 'power'}
                                            ]];
                                        case 'soul':
                                            return [[
                                                {type: 'numbers', title: '排名', width: 80},
                                                {title: '角色名', width: 180, field: 'nick'},
                                                {title: '角色名', width: 180, field: 'pet_name'},
                                                {title: '评分', width: 140, field: 'score'}
                                            ]];
                                        case 'enhance_times':
                                            return [[
                                                {type: 'numbers', title: '排名', width: 80},
                                                {title: '角色名', width: 180, field: 'nick'},
                                                {title: '强化次数', width: 140, field: 'enhance_times'}
                                            ]];
                                        case 'refine_times':
                                            return [[
                                                {type: 'numbers', title: '排名', width: 80},
                                                {title: '角色名', width: 180, field: 'nick'},
                                                {title: '洗练次数', width: 140, field: 'refine_times'}
                                            ]];
                                        case 'wash_times':
                                            return [[
                                                {type: 'numbers', title: '排名', width: 80},
                                                {title: '角色名', width: 180, field: 'nick'},
                                                {title: '洗髓次数', width: 140, field: 'wash_times'}
                                            ]];
                                        case 'tower_floor':
                                            return [[
                                                {type: 'numbers', title: '排名', width: 80},
                                                {title: '角色名', width: 180, field: 'nick'},
                                                {title: '层数', width: 140, field: 'tower_floor'}
                                            ]];
                                        default:
                                            return [[
                                                {type: 'numbers', title: '排名', width: 80},
                                                {title: '角色名', width: 180, field: 'nick'}
                                            ]];
                                    }
                                };
                                return mapCols(typeVal);
                            })()
                        }, 'data');
                    }
                    return false;
                });



                

     

            });
        }
    })

</script>
</body>
</html>